<template>
  <div class="miusc_list">
    <div class="header">
      <div class="left">发现好歌单</div>
      <div class="right">查看更多</div>
    </div>
    <div class="miusc_lists">
        <div class="swiper-container" id="miusc_lists">
          <div class="swiper-wrapper">
            <div v-for="(item,i) in state.list" @click="to_view(item.id)" class="swiper-slide">
              <div class="top">
                <div class="playCount">
                  <svg class="icon" aria-hidden="true">
                    <use xlink:href="#icon-bofang1"></use>
                  </svg>
                  {{changeValue(item.playCount)}}
                </div>
                <img :src="item.picUrl" alt="">
              </div>
              <div class="name">{{item.name}}</div>
            </div>
          </div>
        </div>
    </div>
  </div>
</template>

<script>
import Swiper from "swiper";
import 'swiper/css/swiper.css'
import {personalized} from "@/api/index"
import {reactive,onMounted,onUpdated} from "vue";
import {useRouter } from "vue-router";
export default {
  setup(){
    let state=reactive({
      list:[]
    })
    //引入router
    let router=useRouter();

    let changeValue=num=>{
      if(num > 100000000){
        return (num/100000000).toFixed(2)+"亿"
      }
      if(num > 10000) {
        return (num/10000).toFixed(2)+"万"
      }
    }
    let to_view=(id)=>{
      router.push({
        name:"listview",
        query:{ "id":id}
      })
    }
    onMounted(async ()=>{
      let res = await personalized()
      state.list=res.data.result
    })
    onUpdated(()=>{
        var swiper = new Swiper('#miusc_lists', {
        slidesPerView: 3,
        spaceBetween: 10,
        });
    })
    return {
      state,changeValue,to_view
    }
  }
}

// export default {
//   data(){
//     return {
//       list:[]
//     }
//   },
//   methods:{
//     changeValue(num){
//       if(num > 100000000){
//         return (num/100000000).toFixed(2)+"亿"
//       }
//       if(num > 10000) {
//         return (num/10000).toFixed(2)+"万"
//       }
//     }
//   },
//   async mounted() {
//     let res = await personalized()
//     console.log(res)
//     this.list=res.data.result
//   },
//   updated() {
//     var swiper = new Swiper('#miusc_lists', {
//       slidesPerView: 3,
//       spaceBetween: 10,
//     });
//   }
// }
</script>

<style lang="less" scoped>
.miusc_list{
  width: 7.1rem;
  margin: .5rem  auto 0 auto;
  .header{
    display: flex;
    justify-content: space-between;
    padding: 0 .3rem;
    .right{
      font-size: .20rem;
      border-radius: .2rem;
      border: .01rem solid #ededed;
      padding: 0 .2rem;
    }
  }
}

.miusc_lists{
  margin-top: .3rem;
  width: 100%;
}
.swiper-slide{
  .name{
    font-size: 0.24rem;
    height: .8rem;
    line-height: .4rem;
    overflow: hidden;
  }
  .top{
    position: relative;
    img{
      width: 100%;
      height: auto;
    }
    .icon{
      width: 0.5rem!important;
      height:0.5rem!important;
      transform: translateY(.1rem);
    }
    .playCount{
      position: absolute;
      right: 0;
      top: 0rem;
      color: #fff;
      font-size: 0.20rem;
      height: .4rem;
      line-height: .4rem;
      transform: translateY(-.1rem);
    }
  }
}
.swiper-wrapper{
  img{
    width: 100%;
    height: auto;
  }
}

</style>